home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / mweb / MWEB Utils / ws295sdk.exe / Ws2sdkzp.exe / SAMPLES / WS2CHAT / CHATDLG.C next >
Encoding:
C/C++ Source or Header  |  1997-06-06  |  37.5 KB  |  1,232 lines

  1. /*++
  2.  
  3. Copyright (c) 1995 Intel Corp
  4.  
  5. Module Name:
  6.  
  7.     dialog.c
  8.  
  9. Abstract:
  10.  
  11.     Contains dialog-box procedures for the WinSock2 Chat sample
  12.     application.  See ws2chat.rc for the actual resource script.
  13.  
  14. --*/
  15.  
  16. #include "nowarn.h"  /* turn off benign warnings */
  17. #ifndef _WINSOCKAPI_
  18. #define _WINSOCKAPI_   /* Prevent inclusion of winsock.h in windows.h */
  19. #endif
  20.  
  21. #include <windows.h>
  22. #include <winsock2.h>
  23. #include "nowarn.h"  /* some warnings may have been turned back on */
  24. #include <ws2atm.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <assert.h>
  28. #include "ws2chat.h"
  29. #include "chatsock.h"
  30. #include "chatdlg.h"
  31. #include "resource.h"
  32.  
  33.  
  34.  
  35.  
  36.  
  37. BOOL APIENTRY
  38. ChooseFamilyDlgProc(
  39.     IN HWND DialogWindow,
  40.     IN UINT Message,
  41.     IN WPARAM WParam,
  42.     IN LPARAM LParam)
  43. /*++
  44.  
  45. Routine Description:
  46.  
  47.     Callback function that processes messages sent to the 'Choose
  48.     Family' dialog box.
  49.  
  50. Implementation
  51.  
  52.     This dialog box is used to query the user as to which supported
  53.     protocol he wishes to use for the chat connection he wishes to
  54.     make.  The available protocols are listed in the IDC_FAM_LB
  55.     listbox via the FillInFamilies function in socket.c.
  56.  
  57.     It is expected that this dialog box gets the WM_INITDIALOG
  58.     message with a LParam that is a pointer to the CONNDATA structure
  59.     for the impending connection.  The result of this function is that
  60.     the ProtocolInfo field of the ConnData struct is filled with a
  61.     pointer to the protocol information structure the user chose in
  62.     the listbox.
  63.  
  64. Arguments:
  65.  
  66.     DialogWindow - Supplies handle of the dialog box.
  67.  
  68.     Message - Supplies the message identifier
  69.  
  70.     WParam - Supplies the first message parameter
  71.  
  72.     LParam - Supplies the second message parameter
  73.  
  74. Return Value:
  75.  
  76.     TRUE -- This function handled the message.
  77.  
  78.     FALSE -- This function did not handle the message.
  79.  
  80. --*/
  81. {
  82.     int              LBIndex;         // index of the item chosen
  83.     static PCONNDATA ConnData = NULL; // connection-specific data
  84.  
  85.     switch (Message) {
  86.  
  87.     case WM_INITDIALOG:
  88.  
  89.         // Get the parameter and fill in the listbox with the
  90.         // available protocols.
  91.         ConnData = (PCONNDATA)LParam;
  92.         assert(ConnData != NULL);
  93.         if (!FillInFamilies(DialogWindow, IDC_FAM_LB)) {
  94.             MessageBox(DialogWindow, "FillInFamilies failed.", "Error.",
  95.                         MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  96.             EndDialog(DialogWindow, FALSE);
  97.         }
  98.  
  99.         return(TRUE);
  100.  
  101.     case WM_COMMAND:
  102.  
  103.         switch (WParam) {
  104.  
  105.         case IDOK:
  106.  
  107.             // Get the index of the listbox item the user has chosen.
  108.             LBIndex = (int)SendMessage(GetDlgItem(DialogWindow, IDC_FAM_LB),
  109.                                   LB_GETCURSEL, 0, 0);
  110.             if (LBIndex == LB_ERR) {
  111.  
  112.                 // Nothing was selected.
  113.                 MessageBox(DialogWindow, "Choose an item, or hit cancel.",
  114.                            "No Selection?",
  115.                            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  116.                 return(TRUE);
  117.             }
  118.  
  119.             // Get the protocol associated with the listbox item the
  120.             // user selected.
  121.             ConnData->ProtocolInfo = GetProtoFromIndex(LBIndex);
  122.             assert(ConnData->ProtocolInfo != NULL);
  123.             EndDialog(DialogWindow, TRUE);
  124.             return(TRUE);
  125.  
  126.         case IDCANCEL:
  127.  
  128.             // Kill the dialog box.
  129.             EndDialog(DialogWindow, FALSE);
  130.             return(TRUE);
  131.  
  132.         default:
  133.  
  134.             return(FALSE);
  135.         } // switch (WParam)
  136.  
  137.     default:
  138.  
  139.         return(FALSE);
  140.     } // switch (Message)
  141.  
  142. } // ChooseFamilyDlgProc()
  143.  
  144.  
  145.  
  146.  
  147. BOOL APIENTRY
  148. InetConnDlgProc(
  149.     IN HWND DialogWindow,
  150.     IN UINT Message,
  151.     IN WPARAM WParam,
  152.     IN LPARAM LParam)
  153.  
  154. /*++
  155.  
  156. Routine Description:
  157.  
  158.     Callback function that processes messages sent to the internet
  159.     connection info dialog box.
  160.  
  161. Implementation
  162.  
  163.     This dialog box gets two strings from the user: the internet
  164.     address and port to which she wants to make a chat connection.
  165.     When the user clicks on the OK button, these two strings are
  166.     converted into a sockaddr_in structure and a pointer to this
  167.     structure is saved in the connection window's CONNDATA structure.
  168.  
  169.     NOTE: No name resolution takes place here!  The address edit
  170.     control expects up to 15 characters, and this string is expected
  171.     to be in.dotted.decimal.notation.  When RNR is available, this is
  172.     where it would be called upon to provide the appropriate
  173.     sockaddr_in structure.  Actually, this dialog box would be
  174.     replaced with a protocol independent name dialog box; RNR would do
  175.     all the rest...
  176.  
  177. Arguments:
  178.  
  179.     DialogWindow - Supplies handle of the dialog box.
  180.  
  181.     Message - Supplies the message identifier
  182.  
  183.     WParam - Supplies the first message parameter
  184.  
  185.     LParam - Supplies the second message parameter
  186.  
  187. Return Value:
  188.  
  189.     TRUE -- This function handled the message.
  190.  
  191.     FALSE -- This function did not handle the message; or the message
  192.     was WM_INITDIALOG and we set the focus.
  193.  
  194. --*/
  195.  
  196. {
  197.     char               PortText[INET_PORT_LEN + 1];   // holds port string
  198.     char               AddressText[INET_ADDR_LEN + 1];// holds addr string
  199.     static PCONNDATA   ConnData = NULL;               // conn-specific data
  200.     struct sockaddr_in *SockAddrInet;                 // Inet socket address
  201.     u_long             InetAddr;                      // Inet-style address
  202.     u_short            InetPort;                      // Inet-style port
  203.     int                Port;                          // intermediate var.
  204.     BOOL               PortStringTranslated;          // for GetDlgItemInt
  205.     struct hostent *host;
  206.  
  207.     switch (Message) {
  208.  
  209.     case WM_INITDIALOG:
  210.  
  211.         // Get the connection data pointer, initialize the dialog box.
  212.         ConnData = (PCONNDATA)LParam;
  213.         assert(ConnData != NULL);
  214.         SendMessage(GetDlgItem(DialogWindow, IDC_INET_ADDRESS),
  215.                     EM_LIMITTEXT, (WPARAM)INET_ADDR_LEN, 0);
  216.         SendMessage(GetDlgItem(DialogWindow, IDC_INET_PORT),
  217.                     EM_LIMITTEXT, (WPARAM)INET_PORT_LEN, 0);
  218.         wsprintf(PortText,"%d", INET_DEFAULT_PORT);
  219.         SendMessage(GetDlgItem(DialogWindow, IDC_INET_PORT),
  220.                     WM_SETTEXT, 0, (LPARAM)PortText);
  221.         SetFocus(GetDlgItem(DialogWindow, IDC_INET_ADDRESS));
  222.         return(FALSE);
  223.  
  224.     case WM_COMMAND:
  225.  
  226.         switch (WParam) {
  227.  
  228.         case IDOK:
  229.  
  230.             // The user has pressed the 'OK' button.  Extract the
  231.             // internet address into a buffer and check the value the
  232.             // user typed for the port.
  233.             GetDlgItemText(DialogWindow,
  234.                            IDC_INET_ADDRESS,
  235.                            AddressText,
  236.                            INET_ADDR_LEN);
  237.             strcpy(ConnData->PeerAddress, AddressText);
  238.             Port = (int)GetDlgItemInt(DialogWindow,
  239.                                       IDC_INET_PORT,
  240.                                       &PortStringTranslated,
  241.                                       TRUE);
  242.             if ((Port < 0) || (Port > 65535) || !PortStringTranslated) {
  243.               MessageBox(DialogWindow,
  244.                          "Please choose a port between 0 and 65535.",
  245.                          "Bad Port.",
  246.                          MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  247.                 return(TRUE);
  248.             }
  249.  
  250.             // Convert the address string to an unsigned long, and
  251.             // convert the port integer to an unsigned short.  If all
  252.             // goes well, fill in the fields and end the dialog box.
  253.             // If not, inform the user and *don't* kill the dialog box.
  254.             InetAddr = inet_addr(AddressText);
  255.             if (InetAddr == INADDR_NONE) {
  256.                 host = gethostbyname(AddressText);
  257.                 if (host) {
  258.                     InetAddr = *((u_long *)host->h_addr_list[0]);
  259.                 }
  260.             }
  261.             InetPort = (u_short)Port;
  262.             if ((InetAddr != INADDR_NONE) && (InetAddr != 0)) {
  263.  
  264.                 // Allocate memory for an internet-style socket address;
  265.                 // point ConnData->SockAddr at this memory, and
  266.                 // use a local pointer to a struct sockaddr_in to
  267.                 // reference the fields.
  268.                 ConnData->RemoteSockAddr.len = sizeof(struct sockaddr_in);
  269.                 ConnData->RemoteSockAddr.buf =
  270.                   malloc(ConnData->RemoteSockAddr.len);
  271.                 if (ConnData->RemoteSockAddr.buf == NULL) {
  272.                     ChatSysError("malloc()",
  273.                                  "InetConnDlgProc()",
  274.                                  TRUE);
  275.                 }
  276.  
  277.                 SockAddrInet =
  278.                   (struct sockaddr_in *)ConnData->RemoteSockAddr.buf;
  279.                 SockAddrInet->sin_family = AF_INET;
  280.                 SockAddrInet->sin_port = htons(InetPort);
  281.                 SockAddrInet->sin_addr.S_un.S_addr = InetAddr;
  282.                 EndDialog(DialogWindow, TRUE);
  283.                 return(TRUE);
  284.  
  285.             }
  286.  
  287.             MessageBox(DialogWindow,
  288.                        "Invalid Internet address. Try again or cancel.",
  289.                        "Error", MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  290.             return(TRUE);
  291.  
  292.         case IDCANCEL:
  293.  
  294.             // The user has pressed cancel.  Kill the dialog box.
  295.             EndDialog(DialogWindow, FALSE);
  296.             return(TRUE);
  297.  
  298.         default:
  299.  
  300.             break;
  301.         } // switch (WParam)
  302.  
  303.         break;
  304.     } // switch (Message)
  305.  
  306.     return(FALSE);
  307. } // InetConnDlgProc()
  308.  
  309.  
  310. VOID ShowMessage(
  311.     HWND hWnd,
  312.     PSTR pMsg)
  313.     /*
  314.     Routine Description:
  315.             Just pop up an error message box.
  316.     */
  317. {
  318.     MessageBox(NULL, pMsg, "WS2Test", MB_OK);
  319. } // ShowMessage
  320.  
  321.  
  322. BOOL ScanAtmAddress(
  323.     HWND        hWndDlg,
  324.     ATM_ADDRESS *pAtmAddr)
  325.     /*
  326.         Routine Description:
  327.             Scanner of ATM Address af a field of ATM socket address.
  328.     */
  329. {
  330.     UCHAR textBuf[MAX_ADDRESS_TEXT];
  331.     UINT value[ATM_ADDR_LENGTH];     // for sscanf
  332.     DWORD length;
  333.     int scanResult;
  334.     UINT i;
  335.     HWND hWndControl;
  336.     UINT selection;
  337.  
  338.     hWndControl = GetDlgItem(hWndDlg, IDC_ADDR_TYPE);
  339.     selection = ListBox_GetCurSel(hWndControl);
  340.     pAtmAddr->AddressType = AtmAddrTypeValue[selection];
  341.  
  342.     length = GetDlgItemText(hWndDlg, IDC_ATM_ADDR, textBuf, sizeof(textBuf));
  343.     if (pAtmAddr->AddressType == ATM_E164)
  344.     {
  345.         memcpy(pAtmAddr->Addr, textBuf, length);
  346.         pAtmAddr->NumofDigits = length;
  347.     }
  348.     else if (pAtmAddr->AddressType != SAP_FIELD_ANY)
  349.     {
  350.         scanResult = sscanf(
  351.             textBuf,
  352.             "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x",
  353.             &value[0], &value[1], &value[2], &value[3], &value[4],
  354.             &value[5], &value[6], &value[7], &value[8], &value[9],
  355.             &value[10], &value[11], &value[12], &value[13], &value[14],
  356.             &value[15], &value[16], &value[17], &value[18], &value[19]);
  357.         if (scanResult != ATM_ADDR_LENGTH)
  358.         {
  359.             ShowMessage(hWndDlg, "Invalid value for ATM address.");
  360.             return FALSE;
  361.         } // if
  362.         for (i = 0; i < ATM_ADDR_LENGTH; i++)
  363.         {
  364.             pAtmAddr->Addr[i] = value[i];
  365.         }
  366.         pAtmAddr->NumofDigits = ATM_ADDR_LENGTH;
  367.     }
  368.  
  369.     return TRUE;
  370.  
  371. } // ScanAtmAddress
  372.  
  373.  
  374.  
  375. BOOL ScanAtmBlli(
  376.     HWND hWndDlg,
  377.     ATM_BLLI *pBLLI)
  378.     /*
  379.         Routine Description:
  380.             Scanner of BLLI af a field of ATM socket address.
  381.     */
  382. {
  383.     UCHAR textBuf[MAX_PARSE_TEXT];
  384.     UINT value[ATM_SNAP_ID_LENGTH];
  385.     HWND hWndControl;
  386.     UINT selection;
  387.     UINT length;
  388.     int scanResult;
  389.     UINT i;
  390.  
  391.     hWndControl = GetDlgItem(hWndDlg, IDC_L2PROTO);
  392.     selection = ListBox_GetCurSel(hWndControl);
  393.     pBLLI->Layer2Protocol = AtmBlliL2ProtoValue[selection];
  394.  
  395.     length = GetDlgItemText(hWndDlg, IDC_L2USER_PROTO, textBuf, sizeof(textBuf));
  396.     if (length != 0)
  397.     {
  398.         if (sscanf(textBuf, "%u", &value[0]) != 1)
  399.         {
  400.             ShowMessage(hWndDlg, "Invalid value for user specified layer 2 protocol info.");
  401.             return FALSE;
  402.         } // if
  403.         else
  404.         {
  405.             pBLLI->Layer2UserSpecifiedProtocol = value[0];
  406.         }
  407.     }
  408.     else
  409.     {
  410.         pBLLI->Layer2UserSpecifiedProtocol = SAP_FIELD_ABSENT;
  411.     }
  412.  
  413.     hWndControl = GetDlgItem(hWndDlg, IDC_L3PROTO);
  414.     selection = ListBox_GetCurSel(hWndControl);
  415.     pBLLI->Layer3Protocol = AtmBlliL3ProtoValue[selection];
  416.  
  417.     length = GetDlgItemText(hWndDlg, IDC_L3USER_PROTO, textBuf, sizeof(textBuf));
  418.     if (length != 0)
  419.     {
  420.         if (sscanf(textBuf, "%u", &value[0]) != 1)
  421.         {
  422.             ShowMessage(hWndDlg, "Invalid value for user specified layer 3 protocol info.");
  423.             return FALSE;
  424.         } // if
  425.         else
  426.         {
  427.             pBLLI->Layer3UserSpecifiedProtocol = value[0];
  428.         }
  429.     }
  430.     else
  431.     {
  432.         pBLLI->Layer3UserSpecifiedProtocol = SAP_FIELD_ABSENT;
  433.     }
  434.  
  435.     hWndControl = GetDlgItem(hWndDlg, IDC_L3IPI);
  436.     selection = ListBox_GetCurSel(hWndControl);
  437.     pBLLI->Layer3IPI = AtmBlliL3IpiValue[selection];
  438.  
  439.     length = GetDlgItemText(hWndDlg, IDC_SNAP_ID, textBuf, sizeof(textBuf));
  440.     if (length > 0)
  441.     {
  442.         scanResult = sscanf(
  443.             textBuf,
  444.             "%x.%x.%x.%x.%x",
  445.             &value[0], &value[1], &value[2], &value[3], &value[4]);
  446.         if (scanResult != ATM_SNAP_ID_LENGTH)
  447.         {
  448.             ShowMessage(hWndDlg, "Invalid value for SNAP ID.");
  449.             return FALSE;
  450.         } // if
  451.         for (i = 0; i < ATM_SNAP_ID_LENGTH; i++)
  452.         {
  453.             pBLLI->SnapID[i] = value[i];
  454.         }
  455.     }
  456.     else
  457.     {
  458.         memset(pBLLI->SnapID, 0, ATM_SNAP_ID_LENGTH);
  459.     }
  460.  
  461.     return TRUE;
  462.  
  463. } // ScanBlli
  464.  
  465.  
  466.  
  467. BOOL ScanAtmBhli(
  468.     HWND hWndDlg,
  469.     ATM_BHLI *pBHLI)
  470.     /*
  471.         Routine Description:
  472.             Scanner of BHLI af a field of ATM socket address.
  473.     */
  474. {
  475.     UCHAR textBuf[MAX_PARSE_TEXT];
  476.     UCHAR value[ATM_HL_INFO_LENGTH];
  477.     HWND hWndControl;
  478.     UINT selection;
  479.     UINT length;
  480.     UINT i;
  481.     int scanResult;
  482.  
  483.     hWndControl = GetDlgItem(hWndDlg, IDC_BHLI_TYPE);
  484.     selection = ListBox_GetCurSel(hWndControl);
  485.     pBHLI->HighLayerInfoType = AtmBhliTypeValue[selection];
  486.     if (pBHLI->HighLayerInfoType != BHLI_UserSpecific) {
  487.         ShowMessage(hWndDlg, "Please choose user specific for BHLI type.");
  488.         return FALSE;
  489.     }
  490.  
  491.     length = GetDlgItemText(hWndDlg, IDC_BHLI, textBuf, sizeof(textBuf));
  492.     if (length != 0)
  493.     {
  494.         scanResult = sscanf(
  495.             textBuf,
  496.             "%c%c%c%c%c%c%c%c",
  497.             &value[0], &value[1], &value[2], &value[3],
  498.             &value[4], &value[5], &value[6], &value[7]);
  499.  
  500.         if ((scanResult != ATM_HL_INFO_LENGTH))
  501.         {
  502.             ShowMessage(hWndDlg, "High Layer Information is a string of 8 chars.");
  503.             return FALSE;
  504.         } // if
  505.         pBHLI->HighLayerInfoLength = (DWORD)scanResult;
  506.         for (i = 0; i < pBHLI->HighLayerInfoLength; i++)
  507.         {
  508.             pBHLI->HighLayerInfo[i] = value[i];
  509.         }
  510.     }
  511.     else
  512.     {
  513.         pBHLI->HighLayerInfoLength = 0;
  514.         memset(pBHLI->HighLayerInfo, 0, ATM_HL_INFO_LENGTH);
  515.     }
  516.  
  517.     return TRUE;
  518. } // ScanAtmBhli
  519.  
  520.  
  521. int InitSelection(
  522.     DWORD   InitValue,
  523.     int     NumOfValues,
  524.     DWORD * ValueList)
  525. {
  526.     int i;
  527.     for (i=0; i<NumOfValues; i++) {
  528.         if (InitValue == ValueList[i]) {
  529.             return i;
  530.         }
  531.     }
  532.     return -1;
  533.  
  534. }
  535.  
  536.  
  537. BOOL APIENTRY
  538. ATMSockAddrProc(
  539.     IN HWND DialogWindow,
  540.     IN UINT Message,
  541.     IN WPARAM WParam,
  542.     IN LPARAM LParam)
  543.  
  544. /*++
  545.  
  546. Routine Description:
  547.  
  548.     Callback function that processes messages sent to the native ATM
  549.     connection info dialog box.
  550.  
  551. Implementation
  552.  
  553.     This dialog box gets the ATM socket address for connection party.
  554.  
  555. Arguments:
  556.  
  557.     DialogWindow - Supplies handle of the dialog box.
  558.  
  559.     Message - Supplies the message identifier
  560.  
  561.     WParam - Supplies the first message parameter
  562.  
  563.     LParam - Supplies the second message parameter
  564.  
  565. Return Value:
  566.  
  567.     TRUE -- This function handled the message.
  568.  
  569.     FALSE -- This function did not handle the message; or the message
  570.     was WM_INITDIALOG and we set the focus.
  571.  
  572. --*/
  573.  
  574. {
  575.  
  576.     static PCONNDATA   ConnData = NULL;               // conn-specific data
  577.     HWND hListBox;
  578.     int i;
  579.     UCHAR textBuf[MAX_ERROR_TEXT];
  580.     static struct sockaddr_atm * pATMSockAddr;
  581.     UINT selection;
  582.  
  583.     switch (Message) {
  584.  
  585.         case WM_INITDIALOG:
  586.  
  587.             // Get the connection data pointer, initialize the dialog box.
  588.             pATMSockAddr = (struct sockaddr_atm *)LParam;
  589.             assert(pATMSockAddr != NULL);
  590.  
  591.             //Initialize ATM address type list box
  592.             hListBox = GetDlgItem(DialogWindow, IDC_ADDR_TYPE);
  593.             for (i = 0; i < NUM_ATM_ADDR_TYPES; i++)
  594.             {
  595.                 ListBox_AddString(hListBox, AtmAddrTypeName[i]);
  596.             }
  597.             i = InitSelection(pATMSockAddr->satm_number.AddressType,
  598.                                  NUM_ATM_ADDR_TYPES,
  599.                                  AtmAddrTypeValue);
  600.             if (i>=0) {
  601.                 ListBox_SetCurSel(hListBox, i);
  602.             }
  603.  
  604.             if(AtmAddrTypeValue[i] == SAP_FIELD_ANY) {
  605.                 EnableWindow(GetDlgItem(DialogWindow, IDC_ATM_ADDR), FALSE);
  606.             }
  607.             else {
  608.                 //Initialize ATM address edit box
  609.                 sprintf(textBuf,
  610.                     "%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x",
  611.                     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  612.                 SetDlgItemText(DialogWindow, IDC_ATM_ADDR, textBuf);
  613.             }
  614.  
  615.             //Initialize Layer 2 protocol list box
  616.             hListBox = GetDlgItem(DialogWindow, IDC_L2PROTO);
  617.             for (i = 0; i < NUM_BLLI_L2PROTO; i++)
  618.             {
  619.                 ListBox_AddString(hListBox, AtmBlliL2ProtoName[i]);
  620.             }
  621.             i = InitSelection(pATMSockAddr->satm_blli.Layer2Protocol,
  622.                               NUM_BLLI_L2PROTO,
  623.                               AtmBlliL2ProtoValue);
  624.             if (i>=0) {
  625.                 ListBox_SetCurSel(hListBox, i);
  626.             }
  627.             if (AtmBlliL2ProtoValue[i] != BLLI_L2_USER_SPECIFIED) {
  628.                 EnableWindow(GetDlgItem(DialogWindow, IDC_L2USER_PROTO), FALSE);
  629.             }
  630.  
  631.             //Initialize Layer 3 protocol list box
  632.             hListBox = GetDlgItem(DialogWindow, IDC_L3PROTO);
  633.             for (i = 0; i < NUM_BLLI_L3PROTO; i++)
  634.             {
  635.                 ListBox_AddString(hListBox, AtmBlliL3ProtoName[i]);
  636.             }
  637.             i = InitSelection(pATMSockAddr->satm_blli.Layer3Protocol,
  638.                               NUM_BLLI_L3PROTO,
  639.                               AtmBlliL3ProtoValue);
  640.             if (i>=0) {
  641.                 ListBox_SetCurSel(hListBox, i);
  642.             }
  643.  
  644.             if (AtmBlliL3ProtoValue[i] != BLLI_L3_USER_SPECIFIED) {
  645.                 EnableWindow(GetDlgItem(DialogWindow, IDC_L3USER_PROTO), FALSE);
  646.             }
  647.  
  648.             //Initialize Layer 3 IPI list box
  649.             hListBox = GetDlgItem(DialogWindow, IDC_L3IPI);
  650.             for (i = 0; i < NUM_BLLI_L3IPI; i++)
  651.             {
  652.                 ListBox_AddString(hListBox, AtmBlliL3IpiName[i]);
  653.             }
  654.             i = InitSelection(pATMSockAddr->satm_blli.Layer3IPI,
  655.                               NUM_BLLI_L3IPI,
  656.                               AtmBlliL3IpiValue);
  657.             if (i>=0) {
  658.                 ListBox_SetCurSel(hListBox, i);
  659.             }
  660.  
  661.             if (AtmBlliL3IpiValue[i] != BLLI_L3_IPI_SNAP) {
  662.                 EnableWindow(GetDlgItem(DialogWindow, IDC_SNAP_ID), FALSE);
  663.             }
  664.             else {
  665.                 //Initialize SnapID edit control
  666.                 sprintf(textBuf, "%02x.%02x.%02x.%02x.%02x", 0,0,0,0,0);
  667.                 SetDlgItemText(DialogWindow, IDC_SNAP_ID, textBuf);
  668.             }
  669.  
  670.             if (AtmBlliL3ProtoValue[i] != BLLI_L3_ISO_TR9577) {
  671.                 EnableWindow(GetDlgItem(DialogWindow, IDC_L3IPI), FALSE);
  672.                 EnableWindow(GetDlgItem(DialogWindow, IDC_SNAP_ID), FALSE);
  673.             }
  674.  
  675.             //Initialize high layer info type list box
  676.             hListBox = GetDlgItem(DialogWindow, IDC_BHLI_TYPE);
  677.             for (i = 0; i < NUM_BHLI_TYPES; i++)
  678.             {
  679.                 ListBox_AddString(hListBox, AtmBhliTypeName[i]);
  680.             }
  681.             i = InitSelection(pATMSockAddr->satm_bhli.HighLayerInfoType,
  682.                               NUM_BHLI_TYPES,
  683.                               AtmBhliTypeValue);
  684.             if (i>=0) {
  685.                 ListBox_SetCurSel(hListBox, i);
  686.             }
  687.  
  688.             if (AtmBhliTypeValue[i] == SAP_FIELD_ABSENT ||
  689.                 AtmBhliTypeValue[i] == SAP_FIELD_ANY) {
  690.                 EnableWindow(GetDlgItem(DialogWindow, IDC_BHLI), FALSE);
  691.             }
  692.             else {
  693.                 //Initialize high layer info edit control
  694.                 if (pATMSockAddr->satm_bhli.HighLayerInfoType == BHLI_UserSpecific) {
  695.                     SetDlgItemText(DialogWindow, IDC_BHLI, ATM_DEFAULT_BHLI_INFO);
  696.                 }
  697.             }
  698.  
  699.             return(FALSE);
  700.  
  701.         case WM_COMMAND:
  702.  
  703.             switch ((USHORT)WParam) {
  704.  
  705.                 case IDC_ADDR_TYPE:
  706.                     hListBox = GetDlgItem(DialogWindow, IDC_ADDR_TYPE);
  707.                     selection = ListBox_GetCurSel(hListBox);
  708.                     if (AtmAddrTypeValue[selection] != SAP_FIELD_ANY) {
  709.                         EnableWindow(GetDlgItem(DialogWindow, IDC_ATM_ADDR), TRUE);
  710.                     }
  711.                     else {
  712.                         EnableWindow(GetDlgItem(DialogWindow, IDC_ATM_ADDR), FALSE);
  713.                     }
  714.                     break;
  715.  
  716.                 case IDC_L2PROTO:
  717.                     hListBox = GetDlgItem(DialogWindow, IDC_L2PROTO);
  718.                     selection = ListBox_GetCurSel(hListBox);
  719.                     if (AtmBlliL2ProtoValue[selection] == BLLI_L2_USER_SPECIFIED) {
  720.                         EnableWindow(GetDlgItem(DialogWindow, IDC_L2USER_PROTO), TRUE);
  721.                     }
  722.                     else {
  723.                         EnableWindow(GetDlgItem(DialogWindow, IDC_L2USER_PROTO), FALSE);
  724.                     }
  725.                     break;
  726.  
  727.                 case IDC_L3PROTO:
  728.                     hListBox = GetDlgItem(DialogWindow, IDC_L3PROTO);
  729.                     selection = ListBox_GetCurSel(hListBox);
  730.                     if (AtmBlliL3ProtoValue[selection] == BLLI_L3_USER_SPECIFIED) {
  731.                         EnableWindow(GetDlgItem(DialogWindow, IDC_L3USER_PROTO), TRUE);
  732.                     }
  733.                     else {
  734.                         EnableWindow(GetDlgItem(DialogWindow, IDC_L3USER_PROTO), FALSE);
  735.                     }
  736.                     if (AtmBlliL3ProtoValue[selection] == BLLI_L3_ISO_TR9577) {
  737.                         EnableWindow(GetDlgItem(DialogWindow, IDC_L3IPI), TRUE);
  738.                         hListBox = GetDlgItem(DialogWindow, IDC_L3IPI);
  739.                         selection = ListBox_GetCurSel(hListBox);
  740.                         if (AtmBlliL3IpiValue[selection] == BLLI_L3_IPI_SNAP) {
  741.                             EnableWindow(GetDlgItem(DialogWindow, IDC_SNAP_ID), TRUE);
  742.                         }
  743.                         else {
  744.                             EnableWindow(GetDlgItem(DialogWindow, IDC_SNAP_ID), FALSE);
  745.                         }
  746.                     }
  747.                     else {
  748.                         EnableWindow(GetDlgItem(DialogWindow, IDC_L3IPI), FALSE);
  749.                         EnableWindow(GetDlgItem(DialogWindow, IDC_SNAP_ID), FALSE);
  750.                     }
  751.                     break;
  752.  
  753.                 case IDC_L3IPI:
  754.                     hListBox = GetDlgItem(DialogWindow, IDC_L3IPI);
  755.                     selection = ListBox_GetCurSel(hListBox);
  756.                     if (AtmBlliL3IpiValue[selection] == BLLI_L3_IPI_SNAP) {
  757.                         EnableWindow(GetDlgItem(DialogWindow, IDC_SNAP_ID), TRUE);
  758.                     }
  759.                     else {
  760.                         EnableWindow(GetDlgItem(DialogWindow, IDC_SNAP_ID), FALSE);
  761.                     }
  762.                     break;
  763.  
  764.                 case IDC_BHLI_TYPE:
  765.                     hListBox = GetDlgItem(DialogWindow, IDC_BHLI_TYPE);
  766.                     selection = ListBox_GetCurSel(hListBox);
  767.                     if (AtmBhliTypeValue[selection] == SAP_FIELD_ABSENT ||
  768.                         AtmBhliTypeValue[selection] == SAP_FIELD_ANY) {
  769.                         EnableWindow(GetDlgItem(DialogWindow, IDC_BHLI), FALSE);
  770.                     }
  771.                     else {
  772.                         EnableWindow(GetDlgItem(DialogWindow, IDC_BHLI), TRUE);
  773.                     }
  774.                     break;
  775.  
  776.                 case IDOK:
  777.                     if ((ScanAtmAddress(DialogWindow, &pATMSockAddr->satm_number)) &&
  778.                         (ScanAtmBlli(DialogWindow, &pATMSockAddr->satm_blli)) &&
  779.                         (ScanAtmBhli(DialogWindow, &pATMSockAddr->satm_bhli)))
  780.                     {
  781.                         pATMSockAddr->satm_family = AF_ATM;
  782.                         EndDialog(DialogWindow, TRUE);
  783.                         return TRUE;
  784.                     }
  785.  
  786.                     return FALSE;
  787.  
  788.                 case IDCANCEL:
  789.  
  790.                     // The user has pressed cancel.  Kill the dialog box.
  791.                     EndDialog(DialogWindow, FALSE);
  792.                     return(TRUE);
  793.  
  794.             default:
  795.  
  796.                 break;
  797.             } // switch (WParam)
  798.  
  799.             break;
  800.     } // switch (Message)
  801.  
  802.     return(FALSE);
  803. } // ATMSockAddrProc()
  804.  
  805.  
  806.  
  807.  
  808. BOOL APIENTRY
  809. DefaultConnDlgProc(
  810.     IN HWND DialogWindow,
  811.     IN UINT Message,
  812.     IN WPARAM WParam,
  813.     IN LPARAM LParam)
  814. /*++
  815.  
  816. Routine Description:
  817.  
  818.     Callback function that processes messages sent to the default
  819.     connection info dialog box.
  820.  
  821. Implementation
  822.  
  823.     This dialog box is the default when chat doesn't recognize a
  824.     particular address family.  The user enters actual hex digits and
  825.     the hex value is stored in the SocketAddress associated with the
  826.     connection. Obviously, this requires the user to know how to
  827.     interpret the structure of the socket address for this address
  828.     family.
  829.  
  830. Arguments:
  831.  
  832.     DialogWindow - Supplies handle of the dialog box.
  833.  
  834.     Message - Supplies the message identifier
  835.  
  836.     WParam - Supplies the first message parameter
  837.  
  838.     LParam - Supplies the second message parameter
  839.  
  840. Return Value:
  841.  
  842.     TRUE -- This function handled the message.
  843.  
  844.     FALSE -- This function did not handle the message.
  845.  
  846. --*/
  847. {
  848.  
  849.     static PCONNDATA ConnData = NULL;                // connection data
  850.     static int       AddrLen;                        // length of addresses
  851.     char             AddrText[MAX_SOCKADDR_LEN * 2]; // address string
  852.  
  853.     switch (Message) {
  854.  
  855.     case WM_INITDIALOG:
  856.  
  857.         // Get the parameter and figure out how long addresses for
  858.         // this protocol may be.
  859.         ConnData = (PCONNDATA)LParam;
  860.         assert(ConnData != NULL);
  861.  
  862.         AddrLen = ConnData->ProtocolInfo->iMaxSockAddr;
  863.  
  864.         if (AddrLen > MAX_SOCKADDR_LEN) {
  865.             MessageBox(DialogWindow,
  866.                        "Sorry, socket addresses are too big. Aborting.",
  867.                        "Error.", MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  868.             EndDialog(DialogWindow, FALSE);
  869.         }
  870.  
  871.         // Limit the amount of text in the edit control to twice
  872.         // AddrLen, i.e. 2 hex characters per byte.
  873.         SendMessage(GetDlgItem(DialogWindow, IDC_ADDRESS), EM_LIMITTEXT,
  874.                     (WPARAM)(AddrLen * 2), 0);
  875.         return(TRUE);
  876.  
  877.     case WM_COMMAND:
  878.  
  879.         switch (WParam) {
  880.  
  881.         case IDOK:
  882.  
  883.             // The user clicked 'OK'.  Get the text from the edit
  884.             // control, and convert the hex string into bytes and put
  885.             // the bytes into the socket address for this connection.
  886.             GetDlgItemText(DialogWindow, IDC_ADDRESS, AddrText,
  887.                            MAX_SOCKADDR_LEN * 2);
  888.             ConnData->RemoteSockAddr.len = AddrLen;
  889.             ConnData->RemoteSockAddr.buf =
  890.               malloc(ConnData->RemoteSockAddr.len);
  891.             if (ConnData->RemoteSockAddr.buf == NULL) {
  892.                 ChatSysError("malloc()",
  893.                              "DefaultConnDlgProc()",
  894.                              TRUE);
  895.             }
  896.  
  897.             if (TranslateHex(ConnData->RemoteSockAddr.buf,
  898.                              ConnData->RemoteSockAddr.len,
  899.                              AddrText,
  900.                              DialogWindow)) {
  901.                 EndDialog(DialogWindow, TRUE);
  902.             }
  903.             return(TRUE);
  904.  
  905.         case IDCANCEL:
  906.  
  907.             // Kill the dialog box.
  908.             EndDialog(DialogWindow, FALSE);
  909.             return(TRUE);
  910.  
  911.         default:
  912.  
  913.             return(FALSE);
  914.         } // switch (WParam)
  915.  
  916.     default:
  917.  
  918.         return(FALSE);
  919.     } // switch (Message)
  920.  
  921. } // DefaultConnDlgProc()
  922.  
  923.  
  924.  
  925.  
  926.  
  927. BOOL APIENTRY
  928. NameAndSubjectDlgProc(
  929.     IN HWND DialogWindow,
  930.     IN UINT Message,
  931.     IN WPARAM WParam,
  932.     IN LPARAM LParam)
  933. /*++
  934.  
  935. Routine Description:
  936.  
  937.     Callback function that processes messages sent to the name and
  938.     subject dialog box.
  939.  
  940. Implementation
  941.  
  942.     This dialog box is brought up in MakeConnection (see socket.c)
  943.     only if the protocol for the connection to be made supports
  944.     connection-time data transfer.  The user fills in the two fields
  945.     and this data is packed the WSABUF which is referenced through a
  946.     pointer passed in during WM_INITDIALOG processing.
  947.  
  948. Arguments:
  949.  
  950.     DialogWindow - Supplies handle of the dialog box.
  951.  
  952.     Message - Supplies the message identifier
  953.  
  954.     WParam - Supplies the first message parameter
  955.  
  956.     LParam - Supplies the second message parameter
  957.  
  958. Return Value:
  959.  
  960.     TRUE -- This function handled the message.
  961.  
  962.     FALSE -- This function did not handle the message; or the message
  963.     was WM_INITDIALOG and we set the focus.
  964.  
  965. --*/
  966. {
  967.  
  968.     static LPWSABUF CallerBuffer;            // caller user data
  969.     char            NameText[NAME_LEN + 1];  // name string
  970.     char            SubjectText[SUB_LEN + 1];// subject string
  971.  
  972.     switch (Message) {
  973.  
  974.     case WM_INITDIALOG:
  975.  
  976.         // Get the parameter and initialize the dialog box.
  977.         CallerBuffer = (LPWSABUF)LParam;
  978.         assert(CallerBuffer != NULL);
  979.  
  980.         SendMessage(GetDlgItem(DialogWindow, IDC_CALLERNAME),
  981.                     EM_LIMITTEXT, (WPARAM)NAME_LEN, 0);
  982.         SendMessage(GetDlgItem(DialogWindow, IDC_SUBJECT),
  983.                     EM_LIMITTEXT, (WPARAM)SUB_LEN, 0);
  984.         SetFocus(GetDlgItem(DialogWindow, IDC_CALLERNAME));
  985.         return(FALSE);
  986.  
  987.     case WM_COMMAND:
  988.  
  989.         switch (WParam) {
  990.  
  991.         case IDOK:
  992.  
  993.             // Get the strings the user has typed.
  994.             GetDlgItemText(DialogWindow,
  995.                            IDC_CALLERNAME,
  996.                            NameText,
  997.                            NAME_LEN);
  998.             GetDlgItemText(DialogWindow,
  999.                            IDC_SUBJECT,
  1000.                            SubjectText,
  1001.                            SUB_LEN);
  1002.  
  1003.             CallerBuffer->len = strlen(NameText) + strlen(SubjectText) + 2;
  1004.             CallerBuffer->buf = (char *)malloc(CallerBuffer->len);
  1005.             if (CallerBuffer->buf == NULL) {
  1006.                 ChatSysError("malloc()",
  1007.                              "NameAndSubjectDlgProc()",
  1008.                              TRUE);
  1009.             }
  1010.  
  1011.             if (!PackTwoStrings(CallerBuffer->buf,
  1012.                                 CallerBuffer->len,
  1013.                                 NameText,
  1014.                                 SubjectText)) {
  1015.                 MessageBox(DialogWindow, "PackTwoStrings failed. Aborting.",
  1016.                            "Error.", MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  1017.                 EndDialog(DialogWindow, FALSE);
  1018.             }
  1019.  
  1020.             EndDialog(DialogWindow, TRUE);
  1021.             return(TRUE);
  1022.  
  1023.         case IDCANCEL:
  1024.  
  1025.             // Kill the dialog box.
  1026.             EndDialog(DialogWindow, FALSE);
  1027.             return(TRUE);
  1028.  
  1029.         default:
  1030.  
  1031.             return(FALSE);
  1032.         } // switch (WParam)
  1033.  
  1034.     default:
  1035.  
  1036.         return(FALSE);
  1037.     } // switch (Message)
  1038.  
  1039. } // NameAndSubjectDlgProc()
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045. BOOL APIENTRY
  1046. AcceptConnectionDlgProc(
  1047.     IN HWND DialogWindow,
  1048.     IN UINT Message,
  1049.     IN WPARAM WParam,
  1050.     IN LPARAM LParam)
  1051.  
  1052. /*++
  1053.  
  1054. Routine Description:
  1055.  
  1056.     Callback function that processes messages sent to the
  1057.     AcceptConnection dialog box.  Get's the callee's name and copies
  1058.     it into the CalleeBuffer, which is passed in as a parameter to the
  1059.     WM_INITDIALOG message.
  1060.  
  1061. Arguments:
  1062.  
  1063.     DialogWindow - Supplies handle of the AcceptConnection dialog box
  1064.  
  1065.     Message - Supplies the message identifier
  1066.  
  1067.     WParam - Supplies the first message parameter
  1068.  
  1069.     LParam - Supplies the second message parameter
  1070.  
  1071. Return Value:
  1072.  
  1073.     TRUE -- This function handled the message.
  1074.  
  1075.     FALSE -- This function did not handle the message; or the message
  1076.     was WM_INITDIALOG and we set the focus.
  1077.  
  1078. --*/
  1079.  
  1080. {
  1081.     static LPWSABUF CalleeData; // callee user data
  1082.  
  1083.     switch (Message) {
  1084.  
  1085.     case WM_INITDIALOG:
  1086.  
  1087.         CalleeData = (LPWSABUF)LParam;
  1088.         assert(CalleeData != NULL);
  1089.  
  1090.         // Determine how much room there is in the user data buffer.
  1091.         // Limit the text to NAME_LEN characters, or less if we
  1092.         // don't have room for that many.
  1093.         if (CalleeData->len < (NAME_LEN + 1)) {
  1094.             SendMessage(GetDlgItem(DialogWindow, IDC_CALLERNAME),
  1095.                         EM_LIMITTEXT, (WPARAM)(CalleeData->len - 1),
  1096.                         0);
  1097.         } else {
  1098.             SendMessage(GetDlgItem(DialogWindow, IDC_CALLERNAME),
  1099.                         EM_LIMITTEXT, (WPARAM)NAME_LEN, 0);
  1100.         }
  1101.         SetFocus(GetDlgItem(DialogWindow, IDC_CALLEENAME));
  1102.         return(FALSE);
  1103.  
  1104.     case WM_COMMAND:
  1105.  
  1106.         switch (WParam) {
  1107.  
  1108.         case IDOK:
  1109.  
  1110.             // Get the name from the control and but it in CalleeData.
  1111.             GetDlgItemText(DialogWindow,
  1112.                            IDC_CALLEENAME,
  1113.                            CalleeData->buf,
  1114.                            NAME_LEN);
  1115.             CalleeData->len = strlen(CalleeData->buf + 1);
  1116.             EndDialog(DialogWindow, TRUE);
  1117.             return(TRUE);
  1118.  
  1119.         case IDCANCEL:
  1120.  
  1121.             // Kill the dialog box
  1122.             EndDialog(DialogWindow, FALSE);
  1123.             return(TRUE);
  1124.  
  1125.         default:
  1126.  
  1127.             break;
  1128.  
  1129.         }
  1130.  
  1131.         break;
  1132.     } // switch (Message)
  1133.  
  1134.     return(FALSE);
  1135. } // AcceptConnectionDlgProc()
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141. BOOL APIENTRY
  1142. InetListenPortDlgProc(
  1143.     IN HWND DialogWindow,
  1144.     IN UINT Message,
  1145.     IN WPARAM WParam,
  1146.     IN LPARAM LParam)
  1147. /*++
  1148.  
  1149. Routine Description:
  1150.  
  1151.     Callback function that processes messages sent to the
  1152.     listening port dialog box.
  1153.  
  1154. Arguments:
  1155.  
  1156.     DialogWindow - Supplies handle of the AcceptConnection dialog box
  1157.  
  1158.     Message - Supplies the message identifier
  1159.  
  1160.     WParam - Supplies the first message parameter
  1161.  
  1162.     LParam - Supplies the second message parameter
  1163.  
  1164. Return Value:
  1165.  
  1166.     TRUE -- This function handled the message.
  1167.  
  1168.     FALSE -- This function did not handle the message; or the message
  1169.     was WM_INITDIALOG and we set the focus.
  1170.  
  1171. --*/
  1172. {
  1173.  
  1174.     static struct sockaddr_in *SockAddrInet;             // Inet sockaddress
  1175.     int                       Port;                      // Inet port
  1176.     BOOL                      PortStringTranslated;      // for GetDlgItemInt
  1177.     char                      PortText[INET_PORT_LEN+1]; // Inet port string
  1178.  
  1179.     switch (Message) {
  1180.  
  1181.     case WM_INITDIALOG:
  1182.  
  1183.         // Get the parameter and initialize the dialog box.
  1184.         SockAddrInet = (struct sockaddr_in *)LParam;
  1185.         assert(SockAddrInet != NULL);
  1186.         SendMessage(GetDlgItem(DialogWindow, IDC_LISTEN_PORT),
  1187.                     EM_LIMITTEXT, (WPARAM)INET_PORT_LEN, 0);
  1188.         wsprintf(PortText,"%d", INET_DEFAULT_PORT);
  1189.         SendMessage(GetDlgItem(DialogWindow, IDC_LISTEN_PORT),
  1190.                     WM_SETTEXT, 0, (LPARAM)PortText);
  1191.         SetFocus(GetDlgItem(DialogWindow, IDC_LISTEN_PORT));
  1192.         return(FALSE);
  1193.  
  1194.     case WM_COMMAND:
  1195.  
  1196.         switch (WParam) {
  1197.  
  1198.         case IDOK:
  1199.  
  1200.             // Get the port.
  1201.             Port = (int)GetDlgItemInt(DialogWindow,
  1202.                                       IDC_LISTEN_PORT,
  1203.                                       &PortStringTranslated,
  1204.                                       TRUE);
  1205.             if ((Port < 0) || (Port > 65535) || !PortStringTranslated) {
  1206.                 MessageBox(DialogWindow,
  1207.                            "Please choose a port between 0 and 65535.",
  1208.                            "Bad Port.",
  1209.                            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
  1210.                 return(TRUE);
  1211.             }
  1212.  
  1213.             SockAddrInet->sin_port = htons((u_short)Port);
  1214.             EndDialog(DialogWindow, TRUE);
  1215.             return(TRUE);
  1216.  
  1217.         case IDCANCEL:
  1218.  
  1219.             // Kill the dialog box.
  1220.             EndDialog(DialogWindow, FALSE);
  1221.             return(TRUE);
  1222.  
  1223.         default:
  1224.             break;
  1225.         }
  1226.         break;
  1227.  
  1228.     } // switch (Message)
  1229.  
  1230.     return(FALSE);
  1231. } // InetListenPortDlgProc()
  1232.